GlobalTypeSelector = Ext.extend(Ext.Window, {
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		this.buttons = [
				{
					text : "选择",
					iconCls : "btn-save",
					scope : this,
					handler : function() {
						if (this.callback) {
							if (!this.isSingle) {
								var c = Ext.getCmp("selectedIds").getValue();
								var d = Ext.getCmp("selectedTypes").getValue();
								this.callback.call(this, c, d);
							} else {
								var b = this.rightPanel.getSelectionModel()
										.getSelections();
								if (b.length > 0) {
									this.callback.call(this,
											b[0].data.proTypeId,
											b[0].data.typeName);
								}
							}
						}
						this.close();
					}
				}, {
					text : "取消",
					iconCls : "btn-cancel",
					scope : this,
					handler : function() {
						this.close();
					}
				} ];
		GlobalTypeSelector.superclass.constructor.call(this, {
			title : a.title ? a.title : "分类选择",
			layout : "border",
			height : 480,
			width : 520,
			buttonAlign : "center"
		});
	},
	initUIComponents : function() {
		this.leftPanel = new Ext.tree.TreePanel({
			title : "分类",
			collapsible : true,
			autoScroll : true,
			split : true,
			region : "west",
			width : 140,
			rootVisible : false,
			loader : new Ext.tree.TreeLoader({
				url : __ctxPath + "/system/treeGlobalType.do?catKey="
						+ this.catKey
			}),
			root : new Ext.tree.AsyncTreeNode({
				expanded : true
			}),
			listeners : {
				"click" : function(e) {
					this.selectedNode = e;
					var d = Ext.getCmp("proTypeCenGrid").getStore();
					d.baseParams = {
						parentId : e.id
					};
					d.reload();
				}
			}
		});
		this.store = new Ext.data.JsonStore({
			url : __ctxPath + "/system/subGlobalType.do?catKey=" + this.catKey,
			baseParams : {
				parentId : 0
			},
			root : "result",
			remoteSort : true,
			fields : [ {
				name : "proTypeId",
				type : "int"
			}, "typeName", "nodeKey", "sn" ]
		});
		this.store.load();
		var b = {
			singleSelect : this.isSingle ? this.isSingle : false
		};
		if (!this.isSingle) {
			Ext.apply(b, {
				listeners : {
					"rowselect" : function(d, h, g) {
						var f = Ext.getCmp("selectedIds");
						var e = Ext.getCmp("selectedTypes");
						f.setValue(f.getValue() + g.data.proTypeId + ";");
						e.setValue(e.getValue() + g.data.typeName + ";");
					},
					"rowdeselect" : function(d, h, g) {
						var f = Ext.getCmp("selectedIds");
						var e = Ext.getCmp("selectedTypes");
						f.setValue(f.getValue().replace(g.data.proTypeId + ";",
								""));
						e.setValue(e.getValue().replace(g.data.typeName + ";",
								""));
					}
				}
			});
		}
		var c = new Ext.grid.CheckboxSelectionModel(b);
		var a = new Ext.grid.ColumnModel({
			columns : [ c, new Ext.grid.RowNumberer(), {
				header : "proTypeId",
				dataIndex : "proTypeId",
				hidden : true
			}, {
				header : "名称",
				dataIndex : "typeName",
				editor : new Ext.form.TextField({
					allowBlank : false
				})
			} ],
			defaults : {
				sortable : true,
				menuDisabled : false
			}
		});
		this.rightPanel = new Ext.grid.GridPanel({
			region : "center",
			title : "分类列表",
			id : "proTypeCenGrid",
			store : this.store,
			sm : c,
			cm : a,
			height : 450
		});
		this.items = [ this.leftPanel, this.rightPanel ];
		if (!this.isSingle) {
			this.southPanel = new Ext.Panel({
				region : "south",
				height : 38,
				bodyStyle : "padding:5px",
				border : false,
				layout : "form",
				items : [ {
					xtype : "hidden",
					id : "selectedIds"
				}, {
					xtype : "compositefield",
					fieldLabel : "选择的类型",
					items : [ {
						xtype : "textfield",
						width : 300,
						readOnly : true,
						id : "selectedTypes"
					}, {
						xtype : "button",
						iconCls : "btn-del",
						text : "清除",
						handler : function() {
							Ext.getCmp("selectedIds").setValue("");
							Ext.getCmp("selectedTypes").setValue("");
						}
					} ]
				} ]
			});
			this.items.push(this.southPanel);
		}
	}
});